<template>
    <template v-for="item in props.menuData" :key="`${props.index}-${item.meta.id}`">
        <el-menu-item
        v-if="!item.children || item.children.lenght == 0"
        :index="`${props.index}-${item.meta.id}`"
        @click="handleClick(item, `${props.index}-${item.meta.id}`)"
        >
        <el-icon size="20">
            <component :is="item.meta.icon" />
        </el-icon>
        <span>{{ item.meta.name }}</span>
        </el-menu-item>
        <el-sub-menu v-else :index="`${props.index}-${item.meta.id}`">
        <template #title>
            <el-icon size="20">
            <component :is="item.meta.icon" />
            </el-icon>
            <span>{{ item.meta.name }}</span>
        </template>
        <aside-menu-tree
            :menuData="item.children"
            :index="`${props.index}-${item.meta.id}`"
        ></aside-menu-tree>
        </el-sub-menu>
    </template>
</template>

<script setup>
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';

const props = defineProps(["menuData", "index"]);
// console.log(props, "props");

// 创建Router实例
const router =useRouter()
const store =useStore()
//点击菜单按钮
const handleClick=(item, index)=>{
    // console.log(item)
    store.commit('addMenu', item.meta)
    store.commit('updateSelectMenu', index)
    router.push(item.meta.path)
}
</script>

<style lang="scss" scoped></style>
